<template>
  <div class="content-box">
    <div>
      <nav-title title="基本信息" />
      <edit-line label="姓" :important="true" v-model="basicInfo.lastName"></edit-line>
      <edit-line label="名" :important="true" v-model="basicInfo.firstName"></edit-line>
      <edit-line label="姓名拼音" :important="true" v-model="basicInfo.nameAc"></edit-line>
      <edit-option-line label="性别" :important="true" :showValue="basicInfo.sexValue" :vals="sexVal" v-model="basicInfo.sex"></edit-option-line>
      <edit-option-line label="国籍" :important="true" :vals="couVal" v-model="basicInfo.country"></edit-option-line>
      <edit-date-line label="出生日期" :important="true" v-model="basicInfo.birthdate"></edit-date-line>
      <edit-option-line label="民族" :important="true" :vals="natVal" v-model="basicInfo.ethnicGrpCd"></edit-option-line>
      <edit-line label="籍贯" :important="true" v-model="basicInfo.nativePlaceChn"></edit-line>
      <edit-option-line label="最高学历" :important="true" :vals="heduVal" v-model="basicInfo.highestEducLvl"></edit-option-line>
      <edit-option-line label="最高学位" :important="true" :vals="degreeVal" v-model="basicInfo.cDegree"></edit-option-line>
      <edit-line label="专业" v-model="basicInfo.cMajor"></edit-line>
      <edit-option-line label="就学类型" :important="true" :vals="cTolType2Val" v-model="basicInfo.cTolType2"></edit-option-line>
      <edit-option-line label="毕业类型" :important="true" :vals="cGraTypeVal" v-model="basicInfo.cGraType"></edit-option-line>
      <edit-option-line label="毕业院校" :important="true" :vals="schools" v-model="basicInfo.cSchool"></edit-option-line>
      <edit-line label="其他院校" :important="true" v-model="basicInfo.schoolOth" v-if="basicInfo.cSchool == '其他'"></edit-line>
      <edit-line label="学制" :important="true" type="number" v-model="basicInfo.cSchoolSystem"></edit-line>
      <edit-date-line label="毕业时间" :important="true" v-model="basicInfo.graEndDt"></edit-date-line>
      <edit-line label="第二专业" v-if="basicInfo.platLx== '10'" v-model="basicInfo.secMajor"></edit-line>
      <edit-line label="技术职称" :important="true" v-if="basicInfo.platLx== '10'" v-model="basicInfo.zcJszc"></edit-line>
      <edit-option-line label="职称等级" :important="true" v-if="basicInfo.platLx== '10'" :vals="cPfqTypeVal" v-model="basicInfo.cPfqType"></edit-option-line>
      <!-- <edit-option-line label="大学生届数" ：important="false" v-if="basicInfo.platLx== '10'" :vals="stuNumVal" v-model="basicInfo.stuNum"></edit-option-line> -->
      <edit-option-line label="入职来源" :important="true" :vals="cEmplFromVal" v-model="basicInfo.cEmplFrom"></edit-option-line>
      <edit-line label="推荐人" v-if="basicInfo.platLx== '10'" v-model="basicInfo.perTjr"></edit-line>
      <edit-date-line label="参加工作日期" :important="true" v-model="basicInfo.startDtChn"></edit-date-line>
      <edit-option-line label="婚姻状况" :important="true" :vals="mryVal" v-model="basicInfo.marStatus"></edit-option-line>
      <edit-option-line label="政治面貌" :important="true" :vals="polsVal" v-model="basicInfo.politicalStaChn"></edit-option-line>
      <edit-option-line label="集体户口" :vals="ynList" v-model="basicInfo.jtHukou"></edit-option-line>
      <edit-option-line label="户口性质" :important="true" :vals="cHukTypeVal" v-model="basicInfo.cHukType"></edit-option-line>
      <edit-option-line label="证件类型" :important="true" :vals="itVal" v-model="basicInfo.nationalIdType"></edit-option-line>
      <edit-line label="证件号码" :important="true" v-model="basicInfo.nationalId"></edit-line>
      <edit-date-line label="证件过期日期" :important="true" v-model="basicInfo.natExperDt"></edit-date-line>
      <edit-option-line label="有无驾照" v-if="basicInfo.platLx== '10'" :vals="lcList" v-model="basicInfo.isJiazhao"></edit-option-line>
      <edit-date-line label="驾照开始日期" v-if="basicInfo.platLx== '10'" v-model="basicInfo.jiaZhaoDt1"></edit-date-line>
      <edit-date-line label="驾照结束日期" v-if="basicInfo.platLx== '10'" v-model="basicInfo.jiaZhaoDt2"></edit-date-line>
      <edit-date-line label="行驶证日期" v-if="basicInfo.platLx== '10'" v-model="basicInfo.xingshizDt"></edit-date-line>
      <edit-line label="档案编号" v-model="basicInfo.perDabh"></edit-line>
      <edit-line label="户籍地址" :important="true" v-model="basicInfo.addresslong1"></edit-line>
      <edit-option-line label="爱心基金成员" @on-change="perRhChose" v-if="basicInfo.platLx== '10'" :vals="ynList" v-model="basicInfo.yn"></edit-option-line>
      <edit-date-line label="入会时间" v-if="basicInfo.platLx== '10'" v-model="basicInfo.perRhdt"></edit-date-line>
      <edit-line label="家庭地址" :important="true" v-model="basicInfo.addresslong3"></edit-line>
      <edit-option-line label="是否住宿" v-if="basicInfo.platLx== '10'" :vals="ynList" v-model="basicInfo.yn2"></edit-option-line>
      <edit-option-line label="是否外租房" v-if="basicInfo.platLx== '10'" :vals="ynList" v-model="basicInfo.yn3"></edit-option-line>
      <edit-line label="住宿地址" v-if="basicInfo.platLx== '10'" v-model="basicInfo.addresslong2"></edit-line>
    </div>
    <div class="bsbtn" @click="save">保存</div>
    <div stype="width:100%;height:30px">&nbsp;</div>
  </div>

</template>

<script>
import { Datetime, Group ,PopupRadio, dateFormat } from 'vux'
import CommonUtil from '../../../../components/basic/util'
import EditLine from '../../../../components/basic/EditLine'
import EditDateLine from '../../../../components/basic/EditDateLine'
import EditOptionLine from '../../../../components/basic/EditOptionLine'
import { getSchools, getDicItem, saveBsinfo, getCountry, getNation, getIdType, getQrmsg } from '../../../../api/api'
import { json2Form } from '../../../../util/http'

export default {

  name: 'input-information',
  components: {
    EditLine, EditDateLine, EditOptionLine
  },
  mounted(){
    if(this.$store.state.hid){
      this.basicInfo.rsHireId = this.$store.state.hid
    }
    
    CommonUtil.loadDic(this.sexVal, 'SEX', "xlatshortname","fieldvalue")//性别
    CommonUtil.loadDic(this.heduVal, 'HIGHEST_EDUC_LVL', "xlatshortname","fieldvalue");//最高学历
    CommonUtil.loadDic(this.cTolType2Val, 'C_TOL_TYPE2', "xlatshortname","fieldvalue"); //就学类型
    CommonUtil.loadDic(this.degreeVal, 'C_DEGREE', "xlatshortname","fieldvalue"); //学位
    CommonUtil.loadDic(this.polsVal, 'POLITICAL_STA_CHN', "xlatshortname","fieldvalue"); //政治
    CommonUtil.loadDic(this.mryVal, 'MAR_STATUS', "xlatshortname","fieldvalue");//婚姻
    CommonUtil.loadDic(this.cHukTypeVal, 'C_HUK_TYPE', "xlatshortname","fieldvalue");//户口类型
    CommonUtil.loadDic(this.cEmplFromVal, 'C_EMPL_FROM', "xlatshortname","fieldvalue");//入职来源
    CommonUtil.loadDic(this.cPfqTypeVal, 'C_PFQ_TYPE', "xlatshortname","fieldvalue");//职称等级
    CommonUtil.loadDic(this.cGraTypeVal, 'C_GRA_TYPE', "xlatshortname","fieldvalue");//职称等级
    
    
    this.getcoulb()//国籍
    this.getnatlb()//民族
    this.getIdlb()//证件
    this.getSchools()//学校
    
    
  },
  data() {
    return {
      basicInfo:{},
      sexVal:[],
      couVal:[],
      natVal:[],
      heduVal:[],
      degreeVal:[],
      cTolType2Val:[],
      polsVal:[],
      mryVal:[],
      schools:[],
      itVal:[],
      cHukTypeVal:[],
      cEmplFromVal:[],
      cPfqTypeVal:[],
      cGraTypeVal:[],
      stuNumVal:[],
      hideTwo:'',
      lcList: [{value: '有', key: 'Y'},{value: '无', key: 'N'}],
      ynList: [{value: '是', key: 'Y'},{value: '否', key: 'N'}],
    }
  },
  created() {
    this.getBsif()
  },
  methods: {
    
    save() {
      var that = this
      console.log(this.basicInfo)
      if(!CommonUtil.valid(this, this.basicInfo,"firstName","请输入您的名字") 
        || !CommonUtil.valid(this, this.basicInfo,"lastName","请输入您的姓氏") 
        || !CommonUtil.valid(this, this.basicInfo,"nameAc","请输入姓名拼音") 
        || !CommonUtil.valid(this, this.basicInfo,"sex","请选择您的性别") 
        || !CommonUtil.valid(this, this.basicInfo,"country","请选择您的国籍") 
        || !CommonUtil.valid(this, this.basicInfo,"birthdate","请选择出生日期") 
        || !CommonUtil.valid(this, this.basicInfo,"ethnicGrpCd","请选择民族") 
        || !CommonUtil.valid(this, this.basicInfo,"nativePlaceChn","请输入您的籍贯") 
         
        || !CommonUtil.valid(this, this.basicInfo,"highestEducLvl","请输入最高学历")
        || !CommonUtil.valid(this, this.basicInfo,"cDegree","请输入最高学位")
        || !CommonUtil.valid(this, this.basicInfo,"cMajor","请输入专业")
        || !CommonUtil.valid(this, this.basicInfo,"cTolType2","请输入就学类型")
        || !CommonUtil.valid(this, this.basicInfo,"cGraType","请输入毕业类型")
        || !CommonUtil.valid(this, this.basicInfo,"cSchool","请输入毕业院校")
        || !CommonUtil.valid(this, this.basicInfo,"cSchoolSystem","请输入学制(年)")
        || !CommonUtil.valid(this, this.basicInfo,"graEndDt","请输入毕业时间")
        || !CommonUtil.valid(this, this.basicInfo,"zcJszc","请输入技术职称") 
        || !CommonUtil.valid(this, this.basicInfo,"cPfqType","请输入职称等级")  

        || !CommonUtil.valid(this, this.basicInfo,"cEmplFrom","请选择入职来源") 
        || !CommonUtil.valid(this, this.basicInfo,"startDtChn","请选择参加工作时间") 
        || !CommonUtil.valid(this, this.basicInfo,"marStatus","请选择婚姻状况")
        || !CommonUtil.valid(this, this.basicInfo,"politicalStaChn","请选择政治面貌") 
        || !CommonUtil.valid(this, this.basicInfo,"nationalIdType","请选择证件类型")
        || !CommonUtil.valid(this, this.basicInfo,"nationalId","请输入证件号码")
        || !CommonUtil.valid(this, this.basicInfo,"addresslong1","请输入户籍地")
        || !CommonUtil.valid(this, this.basicInfo,"addresslong3","请输入家庭地址")   


        || !CommonUtil.valid(this, this.basicInfo,"cHukType","请选择户口类型")
        || !CommonUtil.valid(this, this.basicInfo,"natExperDt","请输入身份证到期日期")

        ){
        return;
      }

      if(this.basicInfo.nationalIdType == "10" && !CommonUtil.checkNationId(this.basicInfo.nationalId)) {
        this.$vux.alert.show({
          title: '提示',
          content: '请输入正确的身份证号'
        })
        return
      }
      if(this.basicInfo.platLx== '10' 
        && this.basicInfo.yn == 'Y' && !this.basicInfo.perRhdt) {
        this.$vux.alert.show({
          title: '提示',
          content: '请输入加入基金会时间'
        })
        return
      }

      
      var nowDay = new Date()
      var birthDay = new Date(this.basicInfo.birthdate)
      var betYear = nowDay.getFullYear() - birthDay.getFullYear();
      if(betYear < 16) {
        this.$vux.alert.show({
          title: '提示',
          content: '未满16周岁，请填写正确出生日期'
        })
        return
      } else if (betYear == 16 
            && (nowDay.getMonth() < birthDay.getMonth() 
                || (nowDay.getMonth() == birthDay.getMonth() && nowDay.getDay() < birthDay.getDay())
                )) {
        this.$vux.alert.show({
          title: '提示',
          content: '未满16周岁，请填写正确出生日期'
        })
        return
      }
      if(this.basicInfo.jiaZhaoDt1 && this.basicInfo.jiaZhaoDt2 && this.basicInfo.jiaZhaoDt1 > this.basicInfo.jiaZhaoDt2) {
        this.$vux.alert.show({
          title: '提示',
          content: '驾照日期不正确，请输入正确的日期'
        })
        return
      }

      if(!this.basicInfo.cSchoolSystem) {
        this.basicInfo.cSchoolSystem = 0
      }
      if(!CommonUtil.checkNumber(this.basicInfo.cSchoolSystem)) {
        this.$vux.alert.show({
          title: '提示',
          content: '学制应填写数字'
        })
        return
      }

      that.basicInfo.name = this.basicInfo.lastName+this.basicInfo.firstName
      console.log(that.basicInfo)
      //当前未使用字段，提交时间戳至服务端会报错
      that.basicInfo.cGraduateDate = null;
      saveBsinfo(json2Form(that.basicInfo)).then(res => {
        if(res && res.retCode === '000000' ){
          //保存成功
          this.$vux.alert.show({
            title: '提示',
            content: '保存成功',
            onHide () {
              that.$router.push('/informationCollection/userInfo');
            }
          })
          that.$store.commit('updateHid', {
            hid: that.basicInfo.rsHireId,
            name: that.basicInfo.name
          })
        }else{
          // 显示
          this.$vux.alert.show({
            title: '提示',
            content: res.retMsg
          })
        }
      }).catch (res=>{
        this.$vux.alert.show({
          title: '警告',
          content: '网络异常，请稍后重试'
        })
      })
    },
    perRhChose(){
      if(this.basicInfo.yn == 'Y') {
        if(!this.basicInfo.perRhdt) {
          this.basicInfo.perRhdt = dateFormat(new Date(), 'YYYY-MM-DD')
        }
      } else {
        this.basicInfo.perRhdt = '';
      }
    },
    //国籍
    getcoulb() {
      getCountry().then(res => {
        res.retData.forEach((val) => {
          if (val.country == 'CHN') this.basicInfo.country = val.country;
          this.couVal.push({value: val.descrshort, key: val.country})
        });
      })
    },
    //民族
    getnatlb() {
      getNation().then(res => {
        res.retData.forEach((val) => {
          this.natVal.push({value: val.descrshort, key: val.ethnicGrpCd})
        });
      })
    },
    //学校
    getSchools() {
      getSchools().then(res => {
        res.retData.forEach((val) => {
          this.schools.push({value: val.cSchool, key: val.cSchool})
        });
      })
    },
    //证件
    getIdlb() {
      getIdType().then(res => {
        res.retData.forEach((val) => {
          this.itVal.push({value: val.descr, key: val.nationalIdType})
        })
      })
    },
    
    getBsif() {
      if(this.$route.params.bsifs){
        this.basicInfo = this.$route.params.bsifs
        CommonUtil.fillDateEmpty(this.basicInfo, ['birthdate','graEndDt', 'startDtChn','natExperDt','jiaZhaoDt1','jiaZhaoDt2','xingshizDt','perRhdt'])
        if(this.basicInfo.cSchoolSystem == 0) {
          this.basicInfo.cSchoolSystem = ''
        }
        //届数
        // if(this.basicInfo.platLx == '10') {
        //   var curYear = new Date().getFullYear();
        //   var year = curYear + 4;
        //   for(var i = 1949; i <= year; i ++) {
        //       this.stuNumVal.push(i);
        //   }
        //   this.stuNumVal.push("");
        //   // if(!this.basicInfo.stuNum) {
        //   //   this.basicInfo.stuNum = curYear;
        //   // }
        // }
        if(!this.basicInfo.nationalIdType) {
          this.basicInfo.nationalIdType = "10";
        }
      }
      CommonUtil.fillDateEmpty(this.basicInfo, ['birthdate', 'graEndDt', 'startDtChn', 'natExperDt', 'jiaZhaoDt1', 'jiaZhaoDt2', 'xingshizDt', 'perRhdt'])
    }
  },
  watch: {
    '$route': 'getBsif'
  }
}
</script>
<style type="text/scss" lang="scss">
  @import "./editinfo";
</style>
